import request from './requests.js'
import qs from 'qs'
import {
	add_duty_warehouse_ship_url,
	del_duty_warehouse_ship_url,
	select_all_duty_warehouse_ship_url,
	update_duty_warehouse_ship_url
} from "./setting.js"

import {
	Toast,
	Notify
} from 'vant'

import {
	getLocalTime
} from "./date.js"


export function add_duty_warehouse_ship(duty_id, warehouse_id, callBack) {

	console.log(add_duty_warehouse_ship_url)
	request({
		url: add_duty_warehouse_ship_url,
		method: 'POST',
		data: qs.stringify({ //这里是发送给后台的数据
			duty_id: duty_id,
			warehouse_id: warehouse_id,
		})
	}).then((response) => { //这里使用了ES6的语法
		// console.log(response) //请求成功返回的数据
		let res = response.data.resultBody
		// console.log(res)
		callBack(res)
	}).catch((error) => {
		// console.log(response)
		console.log(error) //请求失败返回的数据
		Notify('接口请求失败，请联系管理员！')
	})
}


export function select_all_duty_warehouse_ship(callBack) {

	// console.log(select_all_odd_url)
	request({
		url: select_all_duty_warehouse_ship_url,
		method: 'GET',

	}).then((response) => { //这里使用了ES6的语法
		// console.log(response) //请求成功返回的数据
		let res = response.data.resultBody.reverse()

		// console.log(res)
		callBack(res)
	}).catch((error) => {
		// console.log(response)
		console.log(error) //请求失败返回的数据
		Notify('接口请求失败，请联系管理员！')
	})
}


export function del_duty_warehouse_ship(duty_id, warehouse_id, callBack) {

	// console.log(select_all_odd_url)
	request({
		url: del_duty_warehouse_ship_url,
		method: 'POST',
		data: qs.stringify({ //这里是发送给后台的数据
			duty_id: duty_id,
			warehouse_id: warehouse_id,
		})

	}).then((response) => { //这里使用了ES6的语法
		// console.log(response) //请求成功返回的数据
		let res = response.data.resultBody

		// console.log(res)
		callBack(res)
	}).catch((error) => {
		// console.log(response)
		console.log(error) //请求失败返回的数据
		Notify('接口请求失败，请联系管理员！')
	})
}


export function update_duty_warehouse_ship(duty_id, warehouse_id,
	out, in_, out_odd, in_odd,
	out_operation, in_operation,

	examine, callBack) {

	// console.log(select_all_odd_url)
	request({
		url: update_duty_warehouse_ship_url,
		method: 'POST',
		data: qs.stringify({ //这里是发送给后台的数据
			duty_id: duty_id,
			warehouse_id: warehouse_id,
			out: out,
			in_: in_,
			out_odd: out_odd,
			in_odd: in_odd,
			out_operation: out_operation,
			in_operation: in_operation,
			examine: examine
		})

	}).then((response) => { //这里使用了ES6的语法
		// console.log(response) //请求成功返回的数据
		let res = response.data.resultBody

		// console.log(res)
		callBack(res)
	}).catch((error) => {
		// console.log(response)
		console.log(error) //请求失败返回的数据
		Notify('接口请求失败，请联系管理员！')
	})
}
